var oldObjArrayGuest = new Array();
var setoldObjArrayGuest = new Array();
var countSetFilterTypeStatus = 0;
var textGuestName = "";
//////////////Start Guest Name Page ////////////////
function searchAll_guestPage(value,e){
	/*if (e.keyCode == 13 && !e.ctrlKey) {
		getReservationRoomManageMentGuestName("textSearch",value);
		$("#SearchAll_guestPage").select();
	}*/
}
function getReservationRoomManageMentGuestName(data,valueSearch){
	clearData();
	waitingDialog({});
	var searchName = $("#SearchAll_guestPage").val();
	if($("#RowpagerGuestNameListRoomManageMent").val() == null){
		getCurrentTabData().lineGuest = 10;
	}else{
		getCurrentTabData().lineGuest = $("#RowpagerGuestNameListRoomManageMent").val();
	}
	if($("#pagerGuestNameListRoomManageMent").val() == null){
		var pagePointer = 1; 
	}else{
		if(valueSearch!=""&&valueSearch!=undefined){
			var pagePointer = valueSearch; 
		}else{
			var pagePointer = 1;
			getCurrentTabData().pagerNumber = 1;
		}
		//var pagePointer = $("#pagerGuestNameListRoomManageMent").val(); 
	}
	if(getCurrentTabData().TypeGuest!=undefined){
		//$($('[setoption=TypeGuest] option[value='+getCurrentTabData().TypeGuest+']')).attr('selected', 'selected');
		$($('[setoption=TypeGuest] :first option[value="'+getCurrentTabData().TypeGuest+'"]')).attr('selected', 'selected')
	}
	var offfset = (getCurrentTabData().lineGuest*pagePointer)-getCurrentTabData().lineGuest;
	var dataOld =  $("#typeCheckReservationGuest").val();
	var firstSelect = $("[setoption=TypeResvGuest]").val();
	var valueDateCheckin = $("#calendar_btw_checkin").attr("dateofbtwcheckin");
	var valueDateCheckout = $("#calendar_btw_checkout").attr("dateofbtwcheckout");
	if(valueDateCheckin!=""&&valueDateCheckout!=""){
		var dateCheckin = $("#calendar_btw_checkin").attr("dateofbtwcheckin");
	  	var dateCheckout = $("#calendar_btw_checkout").attr("dateofbtwcheckout");
	  	$("#calendar_btw_checkin").val($.datepicker.parseDate("yy-mm-dd",dateCheckin).getFormatedString());
		$("#calendar_btw_checkout").val($.datepicker.parseDate("yy-mm-dd",dateCheckout).getFormatedString());
		$('#calendar_btw_checkin').attr('dateofbtwcheckin',dateCheckin);
		$('#calendar_btw_checkout').attr('dateofbtwcheckout',dateCheckout);
		getCurrentTabData().valueDateCheckin = dateCheckin;
		getCurrentTabData().valueDateCheckout = dateCheckout;
	}else{
		/*var dateCheckin = new Date().toSystemFormat();
		var dateCheckout= new Date().toSystemFormat();
		$("#calendar_btw_checkin").val($.datepicker.parseDate("yy-mm-dd",dateCheckin).getFormatedString());
		$("#calendar_btw_checkout").val($.datepicker.parseDate("yy-mm-dd",dateCheckout).getFormatedString());
		$('#calendar_btw_checkin').attr('dateofbtwcheckin',dateCheckin);
		$('#calendar_btw_checkout').attr('dateofbtwcheckout',dateCheckout);
		getCurrentTabData().valueDateCheckin = dateCheckin;
		getCurrentTabData().valueDateCheckout = dateCheckout;*/
	}
	if(data=="GuestNameListRoomManageMent"){
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}else if(data=="G"){
		getCurrentTabData().typeReservationGuest = dataOld;
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}else if(data=="S"){
		getCurrentTabData().typeReservationGuest = dataOld;
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}else if(data=="A"){
		getCurrentTabData().typeReservationGuest = dataOld;
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}else if(data=="reservationType_A"){
		getCurrentTabData().TypeGuest = data;
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}else if(data=="Checked-out Rooms"){
		getCurrentTabData().TypeGuest = data;
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}else if(data=="Checked-in Rooms"){
		getCurrentTabData().TypeGuest = data;
		typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect);
	}/*else if(data == "textSearch"){
		showDataResRoomManageMentGuestName(data,"textSearch");
	}*/else if(data = "dateSearch"){
		var valueDateCheckin = $("#calendar_btw_checkin").attr("dateofbtwcheckin");
		var valueDateCheckout = $("#calendar_btw_checkout").attr("dateofbtwcheckout");
		if(valueDateCheckin!=""&&valueDateCheckout!=""){
			var dateCheckin = $("#calendar_btw_checkin").attr("dateofBtwCheckin");
			getCurrentTabData().valueDateCheckin = valueDateCheckin;
			var dateCheckout= $("#calendar_btw_checkout").attr("dateofBtwCheckout");
			var firstSelect = $("[setoption=TypeResvGuest]").val();
			   var dataOld =  $("#typeCheckReservationGuest").val();
			   if(dataOld=="G"){
				   getCurrentTabData().typeReservationGuest = dataOld;
					if(pagePointer>1){
						var link = "/reservationService?func=getReservationAllGuestNameGroup&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)
							+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						var linkSet = "/reservationService?func=getReservationAllGuestNameGroup&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						getCurrentTabData().linkSet = linkSet;
						simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
					}else{
						getCurrentTabData().beforePageGuest = ""; 
						getCurrentTabData().beforeSubPageGuest = "";
						var link = "/reservationService?func=getReservationAllGuestNameGroup&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						simpleservice(link,null,showDataResRoomManageMentGuestName,data);
					}
				}else if(dataOld=="S"){
					getCurrentTabData().typeReservationGuest = dataOld;
					if(pagePointer>1){
						var link = "/reservationService?func=getReservationAllGuestNameSingle&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						var linkSet = "/reservationService?func=getReservationAllGuestNameSingle&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						getCurrentTabData().linkSet = linkSet;
						simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
					}else{
						getCurrentTabData().beforePageGuest = ""; 
						getCurrentTabData().beforeSubPageGuest = "";
						var link = "/reservationService?func=getReservationAllGuestNameSingle&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						simpleservice(link,null,showDataResRoomManageMentGuestName,data);
					}
				}else if(dataOld=="A"){
					getCurrentTabData().typeReservationGuest = dataOld;
					if(pagePointer>1){
						var link = "/reservationService?func=getReservationAllGuestName&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						var linkSet = "/reservationService?func=getReservationAllGuestName&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						getCurrentTabData().linkSet = linkSet;
						simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
					}else{
						getCurrentTabData().beforePageGuest = ""; 
						getCurrentTabData().beforeSubPageGuest = "";
						var link = "/reservationService?func=getReservationAllGuestName&offset="
							+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="
							+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect+"&SearchAll_checkoutPage="+searchName;
						simpleservice(link,null,showDataResRoomManageMentGuestName,data);
					}
				}
		}else{
			$("#calendar_btw_checkin").select();
			closeWaitingDialog();
		}
	}
}
function showDataResRoomManageMentGuestName(data,output){
	var valueDateCheckin = getCurrentTabData().valueDateCheckin;
	var valueDateCheckout = getCurrentTabData().valueDateCheckout;
	if((valueDateCheckin!=""&&valueDateCheckout!="")&&(valueDateCheckin!=undefined&&valueDateCheckout!=undefined)){
		var dateCheckin = valueDateCheckin;
	  	var dateCheckout = valueDateCheckout;
	  	$("#calendar_btw_checkin").val($.datepicker.parseDate("yy-mm-dd",dateCheckin).getFormatedString());
		$("#calendar_btw_checkout").val($.datepicker.parseDate("yy-mm-dd",dateCheckout).getFormatedString());
		$('#calendar_btw_checkin').attr('dateofbtwcheckin',dateCheckin);
		$('#calendar_btw_checkout').attr('dateofbtwcheckout',dateCheckout);
	}
	// set for pager
	getCurrentTabData().tablePager = "tablepagingGuest";
	getCurrentTabData().pagerNumberField = "pagerGuestNameListRoomManageMent";
	getCurrentTabData().functionGetData = "getReservationRoomManageMentGuestName";
	getCurrentTabData().pageName = "GuestNameListRoomManageMent";
	getCurrentTabData().pageNavPosition = "pageNavPositionGuest";
	getCurrentTabData().trCheck = "trGuest";
	if(getCurrentTabData().checkinGuest!=undefined){
		$('#calendar_btw_checkin').val($.datepicker.parseDate("yy-mm-dd",getCurrentTabData().checkinGuest).getFormatedString());
		$('#calendar_btw_checkin').attr('dateofbtwcheckin',getCurrentTabData().checkinGuest);
	}
	if(getCurrentTabData().checkoutGuest!=undefined){
		$('#calendar_btw_checkout').val($.datepicker.parseDate("yy-mm-dd",getCurrentTabData().checkoutGuest).getFormatedString());
		$('#calendar_btw_checkout').attr('dateofBtwCheckout',getCurrentTabData().checkoutGuest);
	}
	if(getCurrentTabData().typeReservationGuest!=undefined){
		$('#typeCheckReservationGuest option[value='+getCurrentTabData().typeReservationGuest+']').attr('selected', 'selected');
	}
	if(data.trim()=="[]"&&output=="dateSearch"){
		oldObjArrayGuest = new Array();
	}
	var textDataEmpty = '<tr clearTr="guestReservation" >'+
	'<td colspan="100%" style="text-align:center;" >'+
	dataEmpty+
	'</td>'+
	'</tr>';
	if(data.trim()=="[]"){
		textGuestName = textDataEmpty;
		$("[clearTr=guestReservation]").remove();
		$("#GuestNameListRoomManageMent_Id_Tr").replaceWith("<tr id=GuestNameListRoomManageMent_Id_Tr ></tr>"+textGuestName);
		textGuestName = '';
	}else{
		$("[clearTr=guestReservation]").remove();
		var objArray = new Array();
		if((data=="textSearch"||data=="G"||data=="S"||data=="A"||data=="reservationType_A"||data=="Checked-out Rooms"||data=="Checked-in Rooms")&&data!="dateSearch"){
			objArray = oldObjArrayGuest;
			objArray = objArray[0];
		}else{
			//if(output=="dateSearch"){$("#SearchAll_guestPage").val("");}
			objArray = JSON.parse(data);
			oldObjArrayGuest = JSON.parse(data);
			objArray = objArray[0];
		}
		var NuberShow = getCurrentTabData().beforePageGuest;
		sortIdRoommanagement(objArray);
		var OldGroupId =0;
		var OptionReservation = 0;
		var OptionCheckout = 0;
		var OptionCheckIn = 0;
		var emailPic = '<img src=../images/components/roommanagement/email.png alt=Note height=15 width=20>';
		var printPci = '<img src=../images/components/roommanagement/print.png alt=Note height=15 width=20>';
		var firstSelect = $("[setoption=TypeResvGuest]").val();
		var valueSearch = $("#SearchAll_guestPage").val();
		var typeReservation =  $("#typeCheckReservationGuest").val();
		var checkBgColor = 0;
		for(var i =0;i<objArray.length;i++){
			if(objArray[i].name!=""&&objArray[i].name!=undefined){
				var nameReservation = objArray[i].name.split(" ");
			}else{
				var nameReservation = "";
			}
			var Objtitle = objArray[i].reservationTitle;
			var ObjgroupId = objArray[i].groupId;
			var ObjId = objArray[i].id;
			/*if(data=="G"||data=="S"||data=="A"||data=="reservationType_A"||data=="Checked-out Rooms"||data=="Checked-in Rooms"){
				$("#SearchAll_guestPage").val("");
			}*/
			//// SET OPTION STATUS RESERVATION
			var statusOption = objArray[i].reservationTitle;
			if(statusOption=="Reserved Rooms"){
				//OptionReservation++;
			}else if(statusOption=="Checked-out Rooms"){
				OptionCheckout++;
			}else if(statusOption=="Checked-in Rooms"){
				OptionCheckIn++;
			}
			if(objArray[i].groupId!="0"){
				if(OldGroupId!=objArray[i].groupIdString){
					if(objArray[i].subList!=undefined){
						//	OldGroupId = objArray[i].groupIdString;
							var setDateFormat = new Date(objArray[i].date);
							var setFateFormatCheckout = setDateFormat.addDate(objArray[i].span);
							groupId = objArray[i].groupIdString;
							///Check StatusGroup
								for(var resCount = 0; resCount<objArray[i].subList.length;resCount++){
									if(getStatusResInGroup=="Reserved Rooms"){
										checkStatusResvResInGroup++;
									}else if(getStatusResInGroup=="Checked-out Rooms"){
										checkStatusCheckoutResInGroup++;
									}else if(getStatusResInGroup=="Temp Rooms"){
										
									}else if(getStatusResInGroup=="Cancel Reservation"){
										checkStatusResInGroup++;
									}else{
										checkStatusCheckInResInGroup++;
									}
									if(checkStatusResInGroup>0){
										showStatusResInGroup = statusCheckinNoFull;
									}else if(checkStatusCheckoutResInGroup>0){
										showStatusResInGroup = statusCheckOut;
									}else if(checkStatusResvResInGroup>0&&checkStatusCheckInResInGroup>0){
										showStatusResInGroup = statusCheckin;
									}else if(checkStatusResvResInGroup>0){
										showStatusResInGroup = statusResv;
									}
								}
							///
								var countResIngroup = 0;
								for(var subRes = 0; subRes<objArray[i].subList.length;subRes++){
									var ObjId = objArray[i].subList[subRes].id;
									var setDateFormatRes = new Date(objArray[i].subList[subRes].date);
									var setFateFormatCheckoutRes = setDateFormatRes.addDate(objArray[i].subList[subRes].span);
									var ShowNameGuest = "";
									/// Name Empty
									if(objArray[i].subList[subRes].name!=undefined){
										ShowNameGuest = objArray[i].subList[subRes].name
									}
									///
									var nameReservation = ShowNameGuest.split(" ");
									var checkContinue = checkedFilter(output,valueSearch,nameReservation,firstSelect,Objtitle,ObjgroupId,typeReservation,ObjId);
									if(checkContinue==1){
										continue;
									}
									if(objArray[i].subList[subRes].reservationTitle=="Reserved Rooms"){
										StatusResInGroup = statusResv;
									}else if(objArray[i].subList[subRes].reservationTitle=="Checked-out Rooms"){
										StatusResInGroup = statusCheckOut;
									}else if(objArray[i].subList[subRes].reservationTitle=="Temp Rooms"){
										StatusResInGroup = statusTempResv;
									}else if(objArray[i].subList[subRes].reservationTitle=="Cancel Reservation"){
										StatusResInGroup = statusCancelCheckin;
									}else{
										StatusResInGroup = statusCheckin;
									}
										if(checkBgColor==0){
											statusRecord = 'dataRecordBot';
											checkBgColor = 1;
										}else{
											statusRecord = 'dataRecordBot';
											checkBgColor =0;
										}
										var showDisplayGuestname = "";
										if(ShowNameGuest==""){
											showDisplayGuestname = '<tr clearTr=guestReservation class="'+statusRecord+'" onclick="if(linkClick==true)noGuestName();"  id="btnEditS" >';
										}else{
											showDisplayGuestname = '<tr clearTr=guestReservation class="'+statusRecord+'" onclick="if(linkClick) CallEditReservedPageWithLoadElement(id,'+objArray[i].subList[subRes].id+')"  id="btnEditS" >';
										}
										
										NuberShow++;
										textGuestName += showDisplayGuestname+
										'<td class="spanDataCenter">'+
										NuberShow+
										'</td>'+
										'<td class="spanDataCenter">' +
											'<span> G'+groupId+'</span>'+
										'</td>'+
										'<td class="spanDataCenter">'+
											'<span  >'+objArray[i].subList[subRes].id+'</span>'+
										'</td>'+
										'<td class="spanDataLeft">'+
											'<span class="guestName">'+ShowNameGuest+'</span>'+
										'</td>'+
										'<td class="spanDataCenter"> '+
											'<span>'+setDateFormatRes.getFormatedString()+'</span>'+
										'</td>'+
										'<td class="spanDataCenter">' +
											'<span>'+setFateFormatCheckoutRes.getFormatedString()+'</span>'+
										'</td>'+
										'<td class="spanDataCenter">'+
											StatusResInGroup+
										'</td>'+
										'<td class="spanDataCenter">'+
											'<span>'+setDateFormatRes.getFormatedString()+'-'+setFateFormatCheckoutRes.getFormatedString()+' / '+objArray[i].subList[subRes].span+'</span>'+
										'</td>'+
										'<td class="spanDataLeft">'+
											'<span><div class="fongwordwarp" >'+objArray[i].subList[subRes].roomTypeName+'('+objArray[i].subList[subRes].roomName+')'+'</div></span>'+
										'</td>'+
										'</tr>';
								}
								nextNumberResIngroup = objArray[i].subList.length;
						OldGroupId = objArray[i].groupIdString; 
						continue;
					}else{
						var ObjId = objArray[i].id;
						var setDateFormatRes = new Date(objArray[i].date);
						var setFateFormatCheckoutRes = setDateFormatRes.addDate(objArray[i].span);
						var ShowNameGuest = "";
						/// Name Empty
						if(objArray[i].name!=undefined){
							ShowNameGuest = objArray[i].name;
						}
						///
						/*var nameReservation = ShowNameGuest.split(" ");
						var checkContinue = checkedFilter(output,valueSearch,nameReservation,firstSelect,Objtitle,ObjgroupId,typeReservation,ObjId);
						if(checkContinue==1){
							continue;
						}*/
						if(objArray[i].reservationTitle=="Reserved Rooms"){
							StatusResInGroup = statusResv;
						}else if(objArray[i].reservationTitle=="Checked-out Rooms"){
							StatusResInGroup = statusCheckOut;
						}else if(objArray[i].reservationTitle=="Temp Rooms"){
							StatusResInGroup = statusTempResv;
						}else if(objArray[i].reservationTitle=="Cancel Reservation"){
							StatusResInGroup = statusCancelCheckin;
						}else{
							StatusResInGroup = statusCheckin;
						}
							if(checkBgColor==0){
								statusRecord = 'dataRecordBot';
								checkBgColor = 1;
							}else{
								statusRecord = 'dataRecordBot';
								checkBgColor =0;
							}
							var showDisplayGuestname = "";
							if(ShowNameGuest==""){
								showDisplayGuestname = '<tr clearTr=guestReservation class="'+statusRecord+'"   id="btnEditS" >';
							}else{
								showDisplayGuestname = '<tr clearTr=guestReservation class="'+statusRecord+'" onclick="if(linkClick) CallEditReservedPageWithLoadElement(id,'+objArray[i].id+')"  id="btnEditS" >';
							}
							NuberShow++;
							textGuestName += showDisplayGuestname+
							'<td class="spanDataCenter">'+
							NuberShow+
							'</td>'+
							'<td class="spanDataCenter">' +
								'<span> G'+groupId+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span  >'+objArray[i].id+'</span>'+
							'</td>'+
							'<td class="spanDataLeft">'+
								'<span class="guestName">'+ShowNameGuest+'</span>'+
							'</td>'+
							'<td class="spanDataCenter"> '+
								'<span>'+setDateFormatRes.getFormatedString()+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">' +
								'<span>'+setFateFormatCheckoutRes.getFormatedString()+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								StatusResInGroup+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span>'+setDateFormatRes.getFormatedString()+'-'+setFateFormatCheckoutRes.getFormatedString()+' / '+objArray[i].span+'</span>'+
							'</td>'+
							'<td class="spanDataLeft">'+
								'<span><div class="fongwordwarp" >'+objArray[i].roomTypeName+'('+objArray[i].roomName+')'+'</div></span>'+
							'</td>'+
							'</tr>';
					}
				}
			}else{
				/*var checkContinue = checkedFilter(output,valueSearch,nameReservation,firstSelect,Objtitle,ObjgroupId,typeReservation,ObjId);
				if(checkContinue==1){
					continue;
				}*/
				res = objArray[i].id;
				var setDateFormat = new Date(objArray[i].date);
				var setFateFormatCheckout = setDateFormat.addDate(objArray[i].span);
				getStatusResInGroup = objArray[i].reservationTitle;
				if(getStatusResInGroup=="Reserved Rooms"){
					showStatusResInGroup = statusResv;
				}else if(getStatusResInGroup=="Checked-out Rooms"){
					showStatusResInGroup = statusCheckOut;
				}else if(getStatusResInGroup=="Temp Rooms"){
					showStatusResInGroup = statusTempResv;
				}else if(getStatusResInGroup=="Cancel Reservation"){
					showStatusResInGroup = statusCancelCheckin;
				}else{
					showStatusResInGroup = statusCheckin;
				}
				if(setDateFormat.getFormatedString()!=undefined){
					if(checkBgColor==0){
						statusRecord = 'dataRecordBot';
						checkBgColor = 1;
					}else{
						statusRecord = 'dataRecordBot';
						checkBgColor =0;
					}
						NuberShow++;
						textGuestName += '<tr clearTr=guestReservation class="'+statusRecord+'" onclick="if(linkClick){ CallEditReservedPageWithLoadElement(id,'+objArray[i].id+')}" id="btnEditS" >'+
						'<td class="spanDataCenter">'+
						NuberShow+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+objArray[i].id+'</span>'+
						'</td>'+
						'<td class="spanDataLeft">'+
							'<span class="guestName" >'+objArray[i].name+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+setDateFormat.getFormatedString()+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+setFateFormatCheckout.getFormatedString()+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+showStatusResInGroup+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+setDateFormat.getFormatedString()+'-'+setFateFormatCheckout.getFormatedString()+' / '+objArray[i].span+'</span>'+
						'</td>'+
						'<td class="spanDataLeft"> '+
							'<span>'+objArray[i].roomTypeName+'('+objArray[i].roomName+')'+'</span>'+
						'</td>'+
					'</tr>';
				}
			}
		}
		if(countSetFilterTypeStatus==0){
			countSetFilterTypeStatus++;
			var firstSelect = $("[setoption=TypeResvGuest]").val();
			if(firstSelect=="reservationType_A"){
				$("[setOption=TypeResvGuest]")[0].options.length = 1;
				$("[setOption=TypeResvGuest]").append( $("<option>").val(value="Checked-out Rooms").html(value=statusCheckOut));
				$("[setOption=TypeResvGuest]").append( $("<option>").val(value="Checked-in Rooms").html(value=statusCheckin));
			}
		}
		if(textGuestName==""){
			textGuestName = textDataEmpty;
		}
		$("#GuestNameListRoomManageMent_Id_Tr").replaceWith("<tr id=GuestNameListRoomManageMent_Id_Tr ></tr>"+textGuestName);
		$(".ui-datepicker-trigger").css("position","relative","top","{0}px","height","{10}px");
		textPrint = textGuestName;
		textGuestName = "";
	}
	dateRoomManageMent({checkin:"calendar_btw_checkin",atrcheckin:"dateofBtwCheckin"},{checkout:"calendar_btw_checkout",atrcheckout:"dateofBtwCheckout"});
	$(".ui-datepicker-trigger").css("margin-top","2px");
	closeWaitingDialog();
	showDataResRoomManageMentSetPageGuest(data,getCurrentTabData().lineGuest);
}

function showDataResRoomManageMentSetPageGuest(data,output){
	$("[clearTr*=guestReservationPage]").remove();
	objArray = JSON.parse(data);
	objArray = objArray[1];
	var textRoomPendingCheckinSetpage = "";
	for(var i =0;i<objArray.length;i++){
		var textSubRes = "";
		if(objArray[i].groupId!="0"){
			var statusRecord = "";
			for(var subRes = 0;subRes<objArray[i].subList.length;subRes++){
				textSubRes += '<tr clearTr=guestReservationPage  ><td></td></tr>';
			}
			textRoomPendingCheckinSetpage += '<tr clearTr=guestReservationPage class="trGuest"><td></td></tr>'+textSubRes;
		}else{
			textRoomPendingCheckinSetpage += '<tr clearTr=guestReservationPage ><td></td></tr>';
		}
	}
	$("[name = GuestNameListRoomManageMent_Id_Tr2]").replaceWith("<tr name=GuestNameListRoomManageMent_Id_Tr2></tr>"+textRoomPendingCheckinSetpage);
	textRoomPendingCheckinSetpage = "";
	textSubRes = "";
	
	showPager(output);
}

function showDataResRoomManageMentSetCountGuest(data,output){
	var subCount = 0;
	var recCount = 0;
	var objArray = new Array();
	if((data=="textSearch"||data=="G"||data=="S"||data=="A"||data=="reservationType_A"||data=="Checked-out Rooms"||data=="Checked-in Rooms")&&data!="dateSearch"){
		objArray = oldObjArrayGuest;
		objArrayCheck = objArray[0];
		objArray = objArray[1];
	}else{
		objArray = JSON.parse(data);
		oldObjArrayGuest = objArray;
		objArrayCheck = objArray[0];
		objArray = objArray[1];
	}
	setoldObjArrayGuest = objArray;
	sortIdRoommanagement(objArray);
	sortIdRoommanagement(objArrayCheck);
	for(var i =0;i<objArray.length;i++){
		if(objArray[i].groupId!="0"){
			if(objArray[i].subList!=undefined){
				if(objArrayCheck[objArrayCheck.length-1].groupId==objArray[i].groupId){
					recCount = recCount+objArrayCheck[objArrayCheck.length-1].subList.length;
					subCount = objArrayCheck[objArrayCheck.length-1].subList.length+1;
					break;
				}else{
					recCount += objArray[i].subList.length;
				}
			}else{
				if(objArrayCheck[objArrayCheck.length-1].groupId==objArray[i].groupId){
					recCount = (i+1);
					break;
				}else{
					recCount++;
				}
			}
		}else{
			if(objArrayCheck[objArrayCheck.length-1].id==objArray[i].id){
				
				recCount = recCount+1;
				break;
			}else{
				recCount++;
			}
		}
	}
	getCurrentTabData().beforePageGuest= (recCount);
	getCurrentTabData().beforeSubPageGuest = subCount;
	simpleservice(getCurrentTabData().linkSet,null,showDataResRoomManageMentGuestName,data);
}

function calendarGuest(){

}
function CheckGuest(linkClick,ShowNameGuest,id,objId){
	if(linkClick){ CallEditReservedPageWithLoadElement(id,objId)}
}


function typeReservationGuestFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,firstSelect){
	var valueDateCheckin = getCurrentTabData().valueDateCheckin;
	var valueDateCheckout = getCurrentTabData().valueDateCheckout;
	if((valueDateCheckin!=""&&valueDateCheckout!="")&&(valueDateCheckin!=undefined&&valueDateCheckout!=undefined)){ 
		if(dataOld=="G"){
		   getCurrentTabData().typeReservationGuest = dataOld;
			if(pagePointer>1){
				var link = "/reservationService?func=getReservationAllGuestNameGroup&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				var linkSet = "/reservationService?func=getReservationAllGuestNameGroup&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				getCurrentTabData().linkSet = linkSet;
				simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
			}else{
				getCurrentTabData().beforePageGuest = ""; 
				getCurrentTabData().beforeSubPageGuest = "";
				var link = "/reservationService?func=getReservationAllGuestNameGroup&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				simpleservice(link,null,showDataResRoomManageMentGuestName,data);
			}
		}else if(dataOld=="S"){
			getCurrentTabData().typeReservationGuest = dataOld;
			if(pagePointer>1){
				var link = "/reservationService?func=getReservationAllGuestNameSingle&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				var linkSet = "/reservationService?func=getReservationAllGuestNameSingle&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				getCurrentTabData().linkSet = linkSet;
				simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
			}else{
				getCurrentTabData().beforePageGuest = ""; 
				getCurrentTabData().beforeSubPageGuest = "";
				var link = "/reservationService?func=getReservationAllGuestNameSingle&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				simpleservice(link,null,showDataResRoomManageMentGuestName,data);
			}
		}else if(dataOld=="A"){
			getCurrentTabData().typeReservationGuest = dataOld;
			if(pagePointer>1){
				var link = "/reservationService?func=getReservationAllGuestName&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				var linkSet = "/reservationService?func=getReservationAllGuestName&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				getCurrentTabData().linkSet = linkSet;
				simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
			}else{
				getCurrentTabData().beforePageGuest = ""; 
				getCurrentTabData().beforeSubPageGuest = "";
				var link = "/reservationService?func=getReservationAllGuestName&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout+"&typereservation="+firstSelect;
				simpleservice(link,null,showDataResRoomManageMentGuestName,data);
			}
		}
	}else{ if(dataOld=="G"){
		   getCurrentTabData().typeReservationGuest = dataOld;
			if(pagePointer>1){
				var link = "/reservationService?func=getReservationAllGuestNameGroup&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)+"&typereservation="+firstSelect;
				var linkSet = "/reservationService?func=getReservationAllGuestNameGroup&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&typereservation="+firstSelect;
				getCurrentTabData().linkSet = linkSet;
				simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
			}else{
				getCurrentTabData().beforePageGuest = ""; 
				getCurrentTabData().beforeSubPageGuest = "";
				var link = "/reservationService?func=getReservationAllGuestNameGroup&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&typereservation="+firstSelect;
				simpleservice(link,null,showDataResRoomManageMentGuestName,data);
			}
		}else if(dataOld=="S"){
			getCurrentTabData().typeReservationGuest = dataOld;
			if(pagePointer>1){
				var link = "/reservationService?func=getReservationAllGuestNameSingle&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)+"&typereservation="+firstSelect;
				var linkSet = "/reservationService?func=getReservationAllGuestNameSingle&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&typereservation="+firstSelect;
				getCurrentTabData().linkSet = linkSet;
				simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
			}else{
				getCurrentTabData().beforePageGuest = ""; 
				getCurrentTabData().beforeSubPageGuest = "";
				var link = "/reservationService?func=getReservationAllGuestNameSingle&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&typereservation="+firstSelect;
				simpleservice(link,null,showDataResRoomManageMentGuestName,data);
			}
		}else if(dataOld=="A"){
			
			getCurrentTabData().typeReservationGuest = dataOld;
			if(pagePointer>1){
				var link = "/reservationService?func=getReservationAllGuestName&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+(pagePointer-1)+"&typereservation="+firstSelect;
				var linkSet = "/reservationService?func=getReservationAllGuestName&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&typereservation="+firstSelect;
				getCurrentTabData().linkSet = linkSet;
				simpleservice(link,null,showDataResRoomManageMentSetCountGuest,getCurrentTabData().lineGuest);
			}else{
				getCurrentTabData().beforePageGuest = ""; 
				getCurrentTabData().beforeSubPageGuest = "";
				var link = "/reservationService?func=getReservationAllGuestName&offset="+offfset+"&line="+getCurrentTabData().lineGuest+"&pagePointer="+pagePointer+"&typereservation="+firstSelect;
				simpleservice(link,null,showDataResRoomManageMentGuestName,data);
			}
		}
	}
}
